package android_fields;

import static android_board.GUIBoard.FIELDHEIGHT;
import static android_board.GUIBoard.FIELDWIDTH;
import static android_board.GUIBoard.FONTSIZE;

import common.GUIColor;

import android.graphics.Typeface;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.widget.RelativeLayout;
import android_board.GUICenter;
import dk.dtu.compute.course02312.matadordel2.MainActivity;
import dk.dtu.compute.course02312.matadordel2.R;

public final class GUIStart extends AndroidField {
//	private static final float IMAGEHEIGHTPART = 0.00f;
	private static final float TITLEHEIGHTPART = 0.79f;
//	private static final float SUBTEXTHEIGHTPART = 0.19f;

	public static class Builder extends AndroidField.Builder<GUIStart.Builder> implements
	iBuilder {
		public Builder() {
			this.title = "Start";
			this.bgColor = new GUIColor(MainActivity.context.getResources().getColor(R.color.startbg));
		}

		@Override
		@SuppressWarnings("synthetic-access")
		public final GUIStart build() {
			return new GUIStart(this.bgColor, this.fgColor, this.title,
					this.subText, this.description);
		}
		public final Builder setTitle(String title) {
			this.title = title;
			return this;
		}
		public final Builder setSubText(String subText) {
			this.subText = subText;
			return this;
		}
		public final Builder setDescription(String description) {
			this.description = description;
			return this;
		}
	}

	private GUIStart(GUIColor bgColor, GUIColor fgColor, String title,
			String subText, String description) {
		super(bgColor, fgColor, title, subText, description);
		this.titleView.setText(this.title);
		this.titleView.setGravity(Gravity.CENTER);
		this.titleView.setTypeface(this.titleView.getTypeface(), Typeface.BOLD);
		int height = (int) (TITLEHEIGHTPART * FIELDHEIGHT);
		RelativeLayout.LayoutParams titleParams = new RelativeLayout.LayoutParams(FIELDWIDTH, height);
		this.subTextView.setText(this.subText);
		this.cell.addView(this.titleView, titleParams);
	}
	@Override
	public void setTitle(String title) {
		if (title.length() < 7)
			this.titleView.setTextSize(TypedValue.COMPLEX_UNIT_SP, FONTSIZE + 8);
		else
			this.titleView.setTextSize(TypedValue.COMPLEX_UNIT_SP, FONTSIZE);
		super.setTitle(title);
	}

	@Override
	public void displayOnCenter() {
		super.displayOnCenter();
		GUICenter.textViews[1].setText(this.title);
		GUICenter.textViews[1].setVisibility(View.VISIBLE);
		GUICenter.textViews[2].setText(this.description);
		GUICenter.textViews[2].setVisibility(View.VISIBLE);
		super.displayCarOnCenter();
	}
}
